<?php

namespace App\Console\Commands\Check;

use App\Models\Check\CheckCmbBankFlow;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class ClearOldCmbBankFlow extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'check:clear-old-check-stream';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '清理旧的招商银行流水';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $count = CheckCmbBankFlow::query()
            ->where('etydat', '<', Carbon::now()->subDays(31)->toDateString())
            ->delete();
        if (is_numeric($count)) {
            $content = '自动清理旧的招商银行流水，本次删除行数：' . $count;
            $this->info($content);
            Log::info($content);
        }
        return 0;
    }
}
